<?php

namespace app\activity\model;

use app\BaseModel;
use think\facade\Db;

/**
 * @mixin think\Model
 */
class ActivityItem extends BaseModel
{
    protected $name = 'lb_activity_item';
    protected $pk = 'id';

    public function getListByFilter($filter ,$page_config = ['page' => 1 ,'page_count' => 20]) {
        $result = Db::name($this->name)
            ->where($filter)
            ->page($page_config['page'] ,$page_config['page_count'])
            ->order('top desc,id desc ')
            ->select();

        return $result;
    }

    public function getAllByIds($ids) {
        $filter['status'] = 1;
        $result = Db::name($this->name)->where(['id' => $ids])->select();

        return $result;
    }

    public function countByFilter($filter) {
        $result = Db::name($this->name)
            ->where($filter)
            ->count();

        return $result;
    }

    public function createOne($data)
    {
        $time = time();
        $data['create_time'] = $time;
        $data['update_time'] = $time;
        $res = $this->insert($data);
        return $res;
    }

    public function updateByfilter($where,$data){
        $data['update_time'] = time();
        $res = $this->strict(false)->where($where)->update($data);
        return $res;
    }


    public function getOne($where)
    {
        $data = $this->where($where)->find();
        return !empty($data)?$data->toArray():$data;
    }



}
